﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ImapX.Parsing.Tokens
{
    public class Literal:Token
    {
        public string Value { get; set; }

        public override string Parse(string input)
        {
            var match = Regex.Match(input, @"\{(?<length>\d+)\}\r\n");

            if (!match.Success) throw new ImapException("Failed to parse length of literal from: " + input);

            int length = Convert.ToInt32(match.Groups["length"].Value);

            string leftover = input.Substring(match.Length);

            Value = leftover.Substring(0, length);

            leftover = leftover.Substring(length);

            return leftover;
        }
    }

    public class Address2: Token
    {
        private NString _name = new NString();
        private NString _adl = new NString();
        private NString _mailbox = new NString();
        private NString _host = new NString();

        public string Name { get { return _name.Value; } }
        public string ADL { get { return _adl.Value; } }
        public string Mailbox { get { return _mailbox.Value; } }
        public string Host { get { return _host.Value; } }

        public string Email { get { return "\"" + Name + "\" " + "<" + Mailbox + "@" + Host + ">"; } }

        public Address2()
        {
            parts = new Token[] { _name, _adl, _mailbox, _host };
        }
    }
}
